package com.fulu.game.bi.controller.market;

import com.fulu.game.bi.common.controller.BaseController;
import com.fulu.game.bi.entity.po.market.HistoryTrendStat;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.entity.vo.market.CommonlyQueryVO;
import com.fulu.game.bi.redis.service.market.HistoryTrendStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 数据总览 - 历史趋势
 */
@RequestMapping("/api/v1/history-trend")
@RestController
public class HistoryTrendStatController extends BaseController {

    @Autowired
    private HistoryTrendStatService historyTrendStatService;

    /**
     * 历史趋势-昨日数据
     */
    @PostMapping("/yesterday")
    public Result yesterday() {
        return Result.success().data(historyTrendStatService.yesterday()).msg("查询成功");
    }

    /**
     * 列表查询
     */
    @PostMapping("/list")
    public Result<List<HistoryTrendStat>> list(CommonlyQueryVO vo) {
        final List<HistoryTrendStat> list = historyTrendStatService.list(vo);

        return Result.success().data(list).msg("查询成功");
    }

    /**
     * 导出
     */
    @PostMapping("/export")
    public void export(CommonlyQueryVO vo) {
        historyTrendStatService.export(vo);
    }

    @PostMapping("/stat")
    public Result stat() {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        cacheMap.put("活跃用户数", "livelyUserNum");
        cacheMap.put("新用户数", "newRegistUserNum");
        cacheMap.put("活跃老用户数", "livelyOldUserNum");

        cacheMap.put("充值总人数", "investUserAll");
        cacheMap.put("充值总金额", "investMoneyAll");
        cacheMap.put("充值总次数", "investNum");

        cacheMap.put("消费总金额", "consumeMoneyAll");
        cacheMap.put("消费总次数", "consumeNum");
        cacheMap.put("消费总人数", "consumeUserAll");

        cacheMap.put("皮皮币充值金额", "pipiMoneyInvestAll");
        cacheMap.put("皮皮币充值次数", "pipiMoneyInvestNum");
        cacheMap.put("皮皮币充值人数", "pipiMoneyInvestUserNum");

        cacheMap.put("钻石充值金额", "virtualMoneyInvestAll");
        cacheMap.put("钻石充值次数", "virtualMoneyInvestNum");
        cacheMap.put("钻石充值人数", "virtualMoneyInvestUserNum");

        cacheMap.put("皮皮币消费金额", "pipiMoneyConsumeAll");
        cacheMap.put("皮皮币消费人数", "pipiMoneyConsumeUserNum");
        cacheMap.put("皮皮币消费次数", "pipiMoneyConsumeNum");

        cacheMap.put("钻石消费金额", "virtualMoneyConsumeAll");
        cacheMap.put("钻石消费次数", "virtaulMoneyConsumeNum");
        cacheMap.put("钻石消费人数", "virtualMoneyConsumeUserNum");

        cacheMap.put("订单支付金额", "orderMoneyAll");
        cacheMap.put("订单支付次数", "orderNum");
        cacheMap.put("订单支付人数", "orderUserNum");

        cacheMap.put("订单退款金额", "refundMoneyAll");
        cacheMap.put("订单退款次数", "refundNum");
        cacheMap.put("订单退款人数", "refundUserNum");

        cacheMap.put("优惠券使用金额", "couponMoneyAll");
        cacheMap.put("优惠券退款金额", "refundCouponMoneyAll");

        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());

        return Result.success().data(list).msg("获取成功");
    }


}
